/**
 * 纹理贴图1
 * @date   2011-4-1
 * @author tianye
 */
package cn.edu.dlut.WingGameDemos;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import cn.edu.dlut.WingGame.Graphic.GLDevice;
import cn.edu.dlut.WingGame.Graphic.GLTexture;
import cn.edu.dlut.WingGame.Tools.FPSCounter;

public class Test3 extends Activity {
	private GLSurfaceView mGLView;
	private MyRender3 mRender;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		// 游戏全屏幕
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		GLDevice.setActivity(this);
		GLDevice.setBKColor(200, 200, 200);
		mGLView = new GLSurfaceView(this);
		mRender = new MyRender3();
		mGLView.setRenderer(mRender);
		setContentView(mGLView);
	}

	@Override
	protected void onPause() {
		super.onPause();
		mGLView.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		mGLView.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
}

class MyRender3 implements GLSurfaceView.Renderer {
	private FPSCounter fps = new FPSCounter();
	private GLTexture tex1 = new GLTexture();
	private GLTexture tex2 = new GLTexture();

	public void onDrawFrame(GL10 gl) {
		GLDevice.onDrawFrame(gl);

		tex1.draw(10, 0, 140, 140);
		tex1.drawEx(170, 0, 140, 140, 0, 0, 150, 150, 0, 1);
		tex2.draw(10, 160, 140, 140);
		tex2.drawEx(170, 160, 140, 140, 0, 0, 130, 130, 0, 1);

		tex1.drawEx(10, 320, 140, 140, 45, 1);
		tex1.drawEx(120, 320, 140, 140, -75, 1);
		tex2.drawEx(170, 320, 140, 140, 0, 0.5f);

		fps.nextFrame();
		fps.drawFPS();
	}

	public void onSurfaceChanged(GL10 gl, int width, int height) {
		GLDevice.onSurfaceChanged(gl, width, height);

	}

	public void onSurfaceCreated(GL10 gl, EGLConfig config) {

		GLDevice.onSurfaceCreated(gl, config);
		tex1.creatTexture("WingGame.png");
		tex2.creatTexture("WingGame.jpg");
		GLDevice.setSkewing(100f, 0f);
	}

}
